﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using PPWMS.DBUtility;
using PPWMS.Model;
namespace PPWMS.DAL
{
    /// <summary>
    /// 数据访问类:Order
    /// </summary>
    public partial class Order
    {
        public Order()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string OrderSubId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tb_Order");
            strSql.Append(" where OrderSubId=@OrderSubId ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50)			};
            parameters[0].Value = OrderSubId;

            return SQLHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PPWMS.Model.OrderModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into tb_Order(");
            strSql.Append("OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark)");
            strSql.Append(" values (");
            strSql.Append("@OrderSubId,@OrderId,@BoxId,@ProdType,@SailingDate,@Destination,@OutPlanDate,@ProdSpeci,@ProdDesc,@Addi,@FrameColor,@LegType,@MatchedInLeg,@FootType,@PanelSpeci,@PanelFeature,@PanelColor,@BoardColor,@BoardMaterial,@EdgeColor,@BackplaneColor,@ChairType,@ChairColor,@SpecialTagsRemarks,@IncludeItemsFlag,@ItemsPerPack,@OrderPackCount,@TotalItemsCount,@CheckedItemsCount,@CompletedPackCount,@LackedPackCount,@PanelWeight,@FrameWeight,@Height,@NetWeight,@GrossWeight,@Volume,@Remark)");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50),
					new SqlParameter("@OrderId", SqlDbType.VarChar,50),
					new SqlParameter("@BoxId", SqlDbType.VarChar,50),
					new SqlParameter("@ProdType", SqlDbType.NVarChar,50),
					new SqlParameter("@SailingDate", SqlDbType.Date,3),
					new SqlParameter("@Destination", SqlDbType.NVarChar,500),
					new SqlParameter("@OutPlanDate", SqlDbType.Date,3),
					new SqlParameter("@ProdSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@ProdDesc", SqlDbType.NVarChar,-1),
					new SqlParameter("@Addi", SqlDbType.NVarChar,50),
					new SqlParameter("@FrameColor", SqlDbType.NVarChar,50),
					new SqlParameter("@LegType", SqlDbType.NVarChar,50),
					new SqlParameter("@MatchedInLeg", SqlDbType.NVarChar,50),
					new SqlParameter("@FootType", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelFeature", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardMaterial", SqlDbType.NVarChar,50),
					new SqlParameter("@EdgeColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BackplaneColor", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairType", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairColor", SqlDbType.NVarChar,50),
					new SqlParameter("@SpecialTagsRemarks", SqlDbType.NVarChar,500),
					new SqlParameter("@IncludeItemsFlag", SqlDbType.Int,4),
					new SqlParameter("@ItemsPerPack", SqlDbType.Int,4),
					new SqlParameter("@OrderPackCount", SqlDbType.Int,4),
					new SqlParameter("@TotalItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CheckedItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CompletedPackCount", SqlDbType.Int,4),
					new SqlParameter("@LackedPackCount", SqlDbType.Int,4),
					new SqlParameter("@PanelWeight", SqlDbType.Decimal,9),
					new SqlParameter("@FrameWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@NetWeight", SqlDbType.Decimal,9),
					new SqlParameter("@GrossWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Remark", SqlDbType.NVarChar,500)};
            parameters[0].Value = model.OrderSubId;
            parameters[1].Value = model.OrderId;
            parameters[2].Value = model.BoxId;
            parameters[3].Value = model.ProdType;
            parameters[4].Value = model.SailingDate;
            parameters[5].Value = model.Destination;
            parameters[6].Value = model.OutPlanDate;
            parameters[7].Value = model.ProdSpeci;
            parameters[8].Value = model.ProdDesc;
            parameters[9].Value = model.Addi;
            parameters[10].Value = model.FrameColor;
            parameters[11].Value = model.LegType;
            parameters[12].Value = model.MatchedInLeg;
            parameters[13].Value = model.FootType;
            parameters[14].Value = model.PanelSpeci;
            parameters[15].Value = model.PanelFeature;
            parameters[16].Value = model.PanelColor;
            parameters[17].Value = model.BoardColor;
            parameters[18].Value = model.BoardMaterial;
            parameters[19].Value = model.EdgeColor;
            parameters[20].Value = model.BackplaneColor;
            parameters[21].Value = model.ChairType;
            parameters[22].Value = model.ChairColor;
            parameters[23].Value = model.SpecialTagsRemarks;
            parameters[24].Value = model.IncludeItemsFlag;
            parameters[25].Value = model.ItemsPerPack;
            parameters[26].Value = model.OrderPackCount;
            parameters[27].Value = model.TotalItemsCount;
            parameters[28].Value = model.CheckedItemsCount;
            parameters[29].Value = model.CompletedPackCount;
            parameters[30].Value = model.LackedPackCount;
            parameters[31].Value = model.PanelWeight;
            parameters[32].Value = model.FrameWeight;
            parameters[33].Value = model.Height;
            parameters[34].Value = model.NetWeight;
            parameters[35].Value = model.GrossWeight;
            parameters[36].Value = model.Volume;
            parameters[37].Value = model.Remark;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PPWMS.Model.OrderModel model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_Order set ");
            strSql.Append("OrderId=@OrderId,");
            strSql.Append("BoxId=@BoxId,");
            strSql.Append("ProdType=@ProdType,");
            strSql.Append("SailingDate=@SailingDate,");
            strSql.Append("Destination=@Destination,");
            strSql.Append("OutPlanDate=@OutPlanDate,");
            strSql.Append("ProdSpeci=@ProdSpeci,");
            strSql.Append("ProdDesc=@ProdDesc,");
            strSql.Append("Addi=@Addi,");
            strSql.Append("FrameColor=@FrameColor,");
            strSql.Append("LegType=@LegType,");
            strSql.Append("MatchedInLeg=@MatchedInLeg,");
            strSql.Append("FootType=@FootType,");
            strSql.Append("PanelSpeci=@PanelSpeci,");
            strSql.Append("PanelFeature=@PanelFeature,");
            strSql.Append("PanelColor=@PanelColor,");
            strSql.Append("BoardColor=@BoardColor,");
            strSql.Append("BoardMaterial=@BoardMaterial,");
            strSql.Append("EdgeColor=@EdgeColor,");
            strSql.Append("BackplaneColor=@BackplaneColor,");
            strSql.Append("ChairType=@ChairType,");
            strSql.Append("ChairColor=@ChairColor,");
            strSql.Append("SpecialTagsRemarks=@SpecialTagsRemarks,");
            strSql.Append("IncludeItemsFlag=@IncludeItemsFlag,");
            strSql.Append("ItemsPerPack=@ItemsPerPack,");
            strSql.Append("OrderPackCount=@OrderPackCount,");
            strSql.Append("TotalItemsCount=@TotalItemsCount,");
            strSql.Append("CheckedItemsCount=@CheckedItemsCount,");
            strSql.Append("CompletedPackCount=@CompletedPackCount,");
            strSql.Append("LackedPackCount=@LackedPackCount,");
            strSql.Append("PanelWeight=@PanelWeight,");
            strSql.Append("FrameWeight=@FrameWeight,");
            strSql.Append("Height=@Height,");
            strSql.Append("NetWeight=@NetWeight,");
            strSql.Append("GrossWeight=@GrossWeight,");
            strSql.Append("Volume=@Volume,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where OrderSubId=@OrderSubId ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderId", SqlDbType.VarChar,50),
					new SqlParameter("@BoxId", SqlDbType.VarChar,50),
					new SqlParameter("@ProdType", SqlDbType.NVarChar,50),
					new SqlParameter("@SailingDate", SqlDbType.Date,3),
					new SqlParameter("@Destination", SqlDbType.NVarChar,500),
					new SqlParameter("@OutPlanDate", SqlDbType.Date,3),
					new SqlParameter("@ProdSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@ProdDesc", SqlDbType.NVarChar,-1),
					new SqlParameter("@Addi", SqlDbType.NVarChar,50),
					new SqlParameter("@FrameColor", SqlDbType.NVarChar,50),
					new SqlParameter("@LegType", SqlDbType.NVarChar,50),
					new SqlParameter("@MatchedInLeg", SqlDbType.NVarChar,50),
					new SqlParameter("@FootType", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelSpeci", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelFeature", SqlDbType.NVarChar,50),
					new SqlParameter("@PanelColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BoardMaterial", SqlDbType.NVarChar,50),
					new SqlParameter("@EdgeColor", SqlDbType.NVarChar,50),
					new SqlParameter("@BackplaneColor", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairType", SqlDbType.NVarChar,50),
					new SqlParameter("@ChairColor", SqlDbType.NVarChar,50),
					new SqlParameter("@SpecialTagsRemarks", SqlDbType.NVarChar,500),
					new SqlParameter("@IncludeItemsFlag", SqlDbType.Int,4),
					new SqlParameter("@ItemsPerPack", SqlDbType.Int,4),
					new SqlParameter("@OrderPackCount", SqlDbType.Int,4),
					new SqlParameter("@TotalItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CheckedItemsCount", SqlDbType.Int,4),
					new SqlParameter("@CompletedPackCount", SqlDbType.Int,4),
					new SqlParameter("@LackedPackCount", SqlDbType.Int,4),
					new SqlParameter("@PanelWeight", SqlDbType.Decimal,9),
					new SqlParameter("@FrameWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Height", SqlDbType.Int,4),
					new SqlParameter("@NetWeight", SqlDbType.Decimal,9),
					new SqlParameter("@GrossWeight", SqlDbType.Decimal,9),
					new SqlParameter("@Volume", SqlDbType.Decimal,9),
					new SqlParameter("@Remark", SqlDbType.NVarChar,500),
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50)};
            parameters[0].Value = model.OrderId;
            parameters[1].Value = model.BoxId;
            parameters[2].Value = model.ProdType;
            parameters[3].Value = model.SailingDate;
            parameters[4].Value = model.Destination;
            parameters[5].Value = model.OutPlanDate;
            parameters[6].Value = model.ProdSpeci;
            parameters[7].Value = model.ProdDesc;
            parameters[8].Value = model.Addi;
            parameters[9].Value = model.FrameColor;
            parameters[10].Value = model.LegType;
            parameters[11].Value = model.MatchedInLeg;
            parameters[12].Value = model.FootType;
            parameters[13].Value = model.PanelSpeci;
            parameters[14].Value = model.PanelFeature;
            parameters[15].Value = model.PanelColor;
            parameters[16].Value = model.BoardColor;
            parameters[17].Value = model.BoardMaterial;
            parameters[18].Value = model.EdgeColor;
            parameters[19].Value = model.BackplaneColor;
            parameters[20].Value = model.ChairType;
            parameters[21].Value = model.ChairColor;
            parameters[22].Value = model.SpecialTagsRemarks;
            parameters[23].Value = model.IncludeItemsFlag;
            parameters[24].Value = model.ItemsPerPack;
            parameters[25].Value = model.OrderPackCount;
            parameters[26].Value = model.TotalItemsCount;
            parameters[27].Value = model.CheckedItemsCount;
            parameters[28].Value = model.CompletedPackCount;
            parameters[29].Value = model.LackedPackCount;
            parameters[30].Value = model.PanelWeight;
            parameters[31].Value = model.FrameWeight;
            parameters[32].Value = model.Height;
            parameters[33].Value = model.NetWeight;
            parameters[34].Value = model.GrossWeight;
            parameters[35].Value = model.Volume;
            parameters[36].Value = model.Remark;
            parameters[37].Value = model.OrderSubId;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string OrderSubId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tb_Order ");
            strSql.Append(" where OrderSubId=@OrderSubId ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50)			};
            parameters[0].Value = OrderSubId;

            int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string OrderSubIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tb_Order ");
            strSql.Append(" where OrderSubId in (" + OrderSubIdlist + ")  ");
            int rows = SQLHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PPWMS.Model.OrderModel GetModel(string OrderSubId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark from tb_Order ");
            strSql.Append(" where OrderSubId=@OrderSubId ");
            SqlParameter[] parameters = {
					new SqlParameter("@OrderSubId", SqlDbType.VarChar,50)			};
            parameters[0].Value = OrderSubId;

            PPWMS.Model.OrderModel model = new PPWMS.Model.OrderModel();
            DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PPWMS.Model.OrderModel DataRowToModel(DataRow row)
        {
            PPWMS.Model.OrderModel model = new PPWMS.Model.OrderModel();
            if (row != null)
            {
                if (row["OrderSubId"] != null)
                {
                    model.OrderSubId = row["OrderSubId"].ToString();
                }
                if (row["OrderId"] != null)
                {
                    model.OrderId = row["OrderId"].ToString();
                }
                if (row["BoxId"] != null)
                {
                    model.BoxId = row["BoxId"].ToString();
                }
                if (row["ProdType"] != null)
                {
                    model.ProdType = row["ProdType"].ToString();
                }
                if (row["SailingDate"] != null && row["SailingDate"].ToString() != "")
                {
                    model.SailingDate = DateTime.Parse(row["SailingDate"].ToString());
                }
                if (row["Destination"] != null)
                {
                    model.Destination = row["Destination"].ToString();
                }
                if (row["OutPlanDate"] != null && row["OutPlanDate"].ToString() != "")
                {
                    model.OutPlanDate = DateTime.Parse(row["OutPlanDate"].ToString());
                }
                if (row["ProdSpeci"] != null)
                {
                    model.ProdSpeci = row["ProdSpeci"].ToString();
                }
                if (row["ProdDesc"] != null)
                {
                    model.ProdDesc = row["ProdDesc"].ToString();
                }
                if (row["Addi"] != null)
                {
                    model.Addi = row["Addi"].ToString();
                }
                if (row["FrameColor"] != null)
                {
                    model.FrameColor = row["FrameColor"].ToString();
                }
                if (row["LegType"] != null)
                {
                    model.LegType = row["LegType"].ToString();
                }
                if (row["MatchedInLeg"] != null)
                {
                    model.MatchedInLeg = row["MatchedInLeg"].ToString();
                }
                if (row["FootType"] != null)
                {
                    model.FootType = row["FootType"].ToString();
                }
                if (row["PanelSpeci"] != null)
                {
                    model.PanelSpeci = row["PanelSpeci"].ToString();
                }
                if (row["PanelFeature"] != null)
                {
                    model.PanelFeature = row["PanelFeature"].ToString();
                }
                if (row["PanelColor"] != null)
                {
                    model.PanelColor = row["PanelColor"].ToString();
                }
                if (row["BoardColor"] != null)
                {
                    model.BoardColor = row["BoardColor"].ToString();
                }
                if (row["BoardMaterial"] != null)
                {
                    model.BoardMaterial = row["BoardMaterial"].ToString();
                }
                if (row["EdgeColor"] != null)
                {
                    model.EdgeColor = row["EdgeColor"].ToString();
                }
                if (row["BackplaneColor"] != null)
                {
                    model.BackplaneColor = row["BackplaneColor"].ToString();
                }
                if (row["ChairType"] != null)
                {
                    model.ChairType = row["ChairType"].ToString();
                }
                if (row["ChairColor"] != null)
                {
                    model.ChairColor = row["ChairColor"].ToString();
                }
                if (row["SpecialTagsRemarks"] != null)
                {
                    model.SpecialTagsRemarks = row["SpecialTagsRemarks"].ToString();
                }
                if (row["IncludeItemsFlag"] != null && row["IncludeItemsFlag"].ToString() != "")
                {
                    model.IncludeItemsFlag = int.Parse(row["IncludeItemsFlag"].ToString());
                }
                if (row["ItemsPerPack"] != null && row["ItemsPerPack"].ToString() != "")
                {
                    model.ItemsPerPack = int.Parse(row["ItemsPerPack"].ToString());
                }
                if (row["OrderPackCount"] != null && row["OrderPackCount"].ToString() != "")
                {
                    model.OrderPackCount = int.Parse(row["OrderPackCount"].ToString());
                }
                if (row["TotalItemsCount"] != null && row["TotalItemsCount"].ToString() != "")
                {
                    model.TotalItemsCount = int.Parse(row["TotalItemsCount"].ToString());
                }
                if (row["CheckedItemsCount"] != null && row["CheckedItemsCount"].ToString() != "")
                {
                    model.CheckedItemsCount = int.Parse(row["CheckedItemsCount"].ToString());
                }
                if (row["CompletedPackCount"] != null && row["CompletedPackCount"].ToString() != "")
                {
                    model.CompletedPackCount = int.Parse(row["CompletedPackCount"].ToString());
                }
                if (row["LackedPackCount"] != null && row["LackedPackCount"].ToString() != "")
                {
                    model.LackedPackCount = int.Parse(row["LackedPackCount"].ToString());
                }
                if (row["PanelWeight"] != null && row["PanelWeight"].ToString() != "")
                {
                    model.PanelWeight = Double.Parse(row["PanelWeight"].ToString());
                }
                if (row["FrameWeight"] != null && row["FrameWeight"].ToString() != "")
                {
                    model.FrameWeight = Double.Parse(row["FrameWeight"].ToString());
                }
                if (row["Height"] != null && row["Height"].ToString() != "")
                {
                    model.Height = int.Parse(row["Height"].ToString());
                }
                if (row["NetWeight"] != null && row["NetWeight"].ToString() != "")
                {
                    model.NetWeight = Double.Parse(row["NetWeight"].ToString());
                }
                if (row["GrossWeight"] != null && row["GrossWeight"].ToString() != "")
                {
                    model.GrossWeight = Double.Parse(row["GrossWeight"].ToString());
                }
                if (row["Volume"] != null && row["Volume"].ToString() != "")
                {
                    model.Volume = Double.Parse(row["Volume"].ToString());
                }
                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT OrderSubId  '订单分序号',OrderId  '订单号',BoxId '箱号',ProdType '产品类别',SailingDate '船期',Destination '目的地',OutPlanDate '出柜周计划',ProdSpeci '产品名称规格',ProdDesc '产品描述',Addi '附件',FrameColor '框架颜色',LegType '腿类型',MatchedInLeg '配套内腿',FootType '脚类型',PanelSpeci '面板规格',PanelFeature '面板特点',PanelColor '面板颜色',BoardColor '台面颜色',BoardMaterial '台面材质',EdgeColor '封边颜色',BackplaneColor '背板颜色',ChairType '椅壳类型',ChairColor '椅壳颜色',SpecialTagsRemarks '特别标签备注',IncludeItemsFlag '分体配件项数',ItemsPerPack '每包件数',OrderPackCount '订单数量',TotalItemsCount '总件数',CheckedItemsCount '验算件数',CompletedPackCount '完成数量',LackedPackCount '尚缺数量',PanelWeight '面板重量',FrameWeight '框架重量',Height '高度',NetWeight '净重',GrossWeight '毛重',Volume '立方数',Remark '备注','修改' '修改','删除' '删除'");
            strSql.Append(" FROM tb_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(OrderModel Order)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT OrderSubId  '订单分序号',OrderId  '订单号',BoxId '箱号',ProdType '产品类别',SailingDate '船期',Destination '目的地',OutPlanDate '出柜周计划',ProdSpeci '产品名称规格',ProdDesc '产品描述',Addi '附件',FrameColor '框架颜色',LegType '腿类型',MatchedInLeg '配套内腿',FootType '脚类型',PanelSpeci '面板规格',PanelFeature '面板特点',PanelColor '面板颜色',BoardColor '台面颜色',BoardMaterial '台面材质',EdgeColor '封边颜色',BackplaneColor '背板颜色',ChairType '椅壳类型',ChairColor '椅壳颜色',SpecialTagsRemarks '特别标签备注',IncludeItemsFlag '分体配件项数',ItemsPerPack '每包件数',OrderPackCount '订单数量',TotalItemsCount '总件数',CheckedItemsCount '验算件数',CompletedPackCount '完成数量',LackedPackCount '尚缺数量',PanelWeight '面板重量',FrameWeight '框架重量',Height '高度',NetWeight '净重',GrossWeight '毛重',Volume '立方数',Remark '备注','修改' '修改','删除' '删除' ");
            strSql.Append(" FROM tb_Order where 1=1 ");
            if (!string.IsNullOrEmpty(Order.OrderSubId))
            {
                strSql.Append(" and  OrderSubId like  '%" + Order.OrderSubId.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.OrderId))
            {
                strSql.Append(" and  OrderId like  '%" + Order.OrderId.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoxId))
            {
                strSql.Append(" and  BoxId like  '%" + Order.BoxId.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdType))
            {
                strSql.Append(" and  ProdType like  '%" + Order.ProdType.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.SailingDate.ToString()))
            {
                strSql.Append(" and  SailingDate like  '%" + Order.SailingDate.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.Destination))
            {
                strSql.Append(" and  Destination like  '%" + Order.Destination.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.OutPlanDate.ToString()))
            {
                strSql.Append(" and  OutPlanDate like  '%" + Order.OutPlanDate.ToString().Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdSpeci))
            {
                strSql.Append(" and  ProdSpeci like  '%" + Order.ProdSpeci.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ProdDesc))
            {
                strSql.Append(" and  ProdDesc like  '%" + Order.ProdDesc.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.Addi))
            {
                strSql.Append(" and  Addi like  '%" + Order.Addi.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.FrameColor))
            {
                strSql.Append(" and  FrameColor like  '%" + Order.FrameColor.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.LegType))
            {
                strSql.Append(" and  LegType like  '%" + Order.LegType + "%'");
            }
            if (!string.IsNullOrEmpty(Order.MatchedInLeg))
            {
                strSql.Append(" and  MatchedInLeg like  '%" + Order.MatchedInLeg.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.FootType))
            {
                strSql.Append(" and  FootType like  '%" + Order.FootType.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelSpeci))
            {
                strSql.Append(" and  PanelSpeci like  '%" + Order.PanelSpeci.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelFeature))
            {
                strSql.Append(" and  PanelFeature like  '%" + Order.PanelFeature.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.PanelColor))
            {
                strSql.Append(" and  PanelColor like  '%" + Order.PanelColor.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoardColor))
            {
                strSql.Append(" and  BoardColor like  '%" + Order.BoardColor.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BoardMaterial))
            {
                strSql.Append(" and  BoardMaterial like  '%" + Order.BoardMaterial.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.EdgeColor))
            {
                strSql.Append(" and  EdgeColor like  '%" + Order.EdgeColor + "%'");
            }
            if (!string.IsNullOrEmpty(Order.BackplaneColor))
            {
                strSql.Append(" and  BackplaneColor like  '%" + Order.BackplaneColor.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ChairType))
            {
                strSql.Append(" and  ChairType like  '%" + Order.ChairType.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.ChairColor))
            {
                strSql.Append(" and  ChairColor like  '%" + Order.ChairColor.Trim() + "%'");
            }
            if (!string.IsNullOrEmpty(Order.SpecialTagsRemarks))
            {
                strSql.Append(" and  SpecialTagsRemarks like  '%" + Order.SpecialTagsRemarks.Trim() + "%'");
            }
            if (Order.IncludeItemsFlag != null)
            {
                strSql.Append(" and  IncludeItemsFlag = " + Order.IncludeItemsFlag.ToString().Trim());
            }
            if (Order.ItemsPerPack != null)
            {
                strSql.Append(" and  ItemsPerPack = " + Order.ItemsPerPack.ToString().Trim());
            }
            if (Order.OrderPackCount != null)
            {
                strSql.Append(" and  OrderPackCount = " + Order.OrderPackCount.ToString().Trim());
            }
            if (Order.TotalItemsCount != null)
            {
                strSql.Append(" and  TotalItemsCount = " + Order.TotalItemsCount.ToString().Trim());
            }
            if (Order.CheckedItemsCount != null)
            {
                strSql.Append(" and  CheckedItemsCount = " + Order.CheckedItemsCount.ToString().Trim());
            }
            if (Order.CompletedPackCount != null)
            {
                strSql.Append(" and  CompletedPackCount = " + Order.CompletedPackCount.ToString().Trim());
            }
            if (Order.LackedPackCount != null)
            {
                strSql.Append(" and  LackedPackCount = " + Order.LackedPackCount.ToString().Trim());
            }
            if (Order.PanelWeight != null)
            {
                strSql.Append(" and  PanelWeight = " + Order.PanelWeight.ToString().Trim());
            }
            if (Order.FrameWeight != null)
            {
                strSql.Append(" and  FrameWeight = " + Order.FrameWeight.ToString().Trim());
            }
            if (Order.Height != null)
            {
                strSql.Append(" and  Height = " + Order.Height.ToString().Trim());
            }
            if (Order.NetWeight != null)
            {
                strSql.Append(" and  NetWeight = " + Order.NetWeight.ToString().Trim());
            }
            if (Order.GrossWeight != null)
            {
                strSql.Append(" and  GrossWeight = " + Order.GrossWeight.ToString().Trim());
            }
            if (Order.Volume != null)
            {
                strSql.Append(" and  Volume = " + Order.Volume.ToString().Trim());
            }
            if (!string.IsNullOrEmpty(Order.Remark))
            {
                strSql.Append(" and  Remark like  '%" + Order.Remark.Trim() + "%'");
            }

            return SQLHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" OrderSubId,OrderId,BoxId,ProdType,SailingDate,Destination,OutPlanDate,ProdSpeci,ProdDesc,Addi,FrameColor,LegType,MatchedInLeg,FootType,PanelSpeci,PanelFeature,PanelColor,BoardColor,BoardMaterial,EdgeColor,BackplaneColor,ChairType,ChairColor,SpecialTagsRemarks,IncludeItemsFlag,ItemsPerPack,OrderPackCount,TotalItemsCount,CheckedItemsCount,CompletedPackCount,LackedPackCount,PanelWeight,FrameWeight,Height,NetWeight,GrossWeight,Volume,Remark ");
            strSql.Append(" FROM tb_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return SQLHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM tb_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = SQLHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.OrderSubId desc");
            }
            strSql.Append(")AS Row, T.*  from tb_Order T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return SQLHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "tb_Order";
            parameters[1].Value = "OrderSubId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return SQLHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod

    }
}

